//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __ELASTOS_MONITOR_H__
#define __ELASTOS_MONITOR_H__

class Monitor : protected DzMutex, public DzCondition
{
public:
    void UninterruptibleEnter()
    {
        DzMutex::UninterruptibleLock();
    }

    void Enter(WaitResult *pResult)
    {
        assert(pResult);
        DzMutex::Lock(pResult);
    }

    void TryUninterruptibleEnter(uint_t ticks, WaitResult *pResult)
    {
        assert(pResult);
        DzMutex::TryUninterruptibleLock(ticks, pResult);
    }

    void TryEnter(uint_t ticks, WaitResult *pResult)
    {
        assert(pResult);
        DzMutex::TryLock(ticks, pResult);
    }

    void Exit()
    {
        DzMutex::Unlock();
    }

    void UninterruptibleWait()
    {
        DzCondition::UninterruptibleWait(this);
    }

    void Wait(WaitResult *pResult)
    {
        assert(pResult);
        DzCondition::Wait(this, pResult);
    }

    void TryUninterruptibleWait(uint_t ticks, uint_t *pResidualTicks,
                    WaitResult *pResult)
    {
        assert(pResult);
        DzCondition::TryUninterruptibleWait(this, ticks, pResidualTicks,
                        pResult);
    }

    void TryWait(uint_t ticks, uint_t *pResidualTicks, WaitResult *pResult)
    {
        assert(pResult);
        DzCondition::TryWait(this, ticks, pResidualTicks, pResult);
    }

private:
    // Disable the following functions
    void UninterruptibleWait(DzMutex *pMutex)
    {
    }
    void Wait(DzMutex *pMutex, WaitResult *pResult)
    {
    }

    void TryUninterruptibleWait(DzMutex *pMutex, uint_t uDueTicks,
                    uint_t *puResidualTicks, WaitResult *pResult)
    {
    }

    void TryWait(DzMutex *pMutex, uint_t uDueTicks, uint_t *puResidualTicks,
                    WaitResult *pResult)
    {
    }
};

#endif //__ELASTOS_MONITOR_H__
